package jp.co.piratealliance.pirateAllianceWeb.service.search.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jp.co.piratealliance.pirateAllianceWeb.dao.search.SearchDao;
import jp.co.piratealliance.pirateAllianceWeb.def.Constants;
import jp.co.piratealliance.pirateAllianceWeb.dto.search.SearchInfoDto;
import jp.co.piratealliance.pirateAllianceWeb.dto.task.TaskFeeDetailInfoDto;
import jp.co.piratealliance.pirateAllianceWeb.helper.CommonHelper;
import jp.co.piratealliance.pirateAllianceWeb.service.search.SearchService;


/**
*
* copyright   pirate alliance team 2014
* @author     panxuejuan
*
*/

public class SearchServiceImpl implements SearchService {

	private SearchDao searchDao;

	public SearchDao getSearchDao() {
		return searchDao;
	}

	public void setSearchDao(SearchDao searchDao) {
		this.searchDao = searchDao;
	}
	
	//查询商品与资源关联表信息
    public List<SearchInfoDto> getSearchListByResourceTypeId(Map<String, String> mapParameter){
    	return searchDao.selectSearchListByResourceTypeId(mapParameter);
    }
    
    //选择资源，更新商品受注明细
    public void updateGoodsDetailInfo(TaskFeeDetailInfoDto taskFeeDetailInfo){
    		Map<String,Object> paraMap =new HashMap<String,Object>();
    		paraMap.put("goods_id", taskFeeDetailInfo.getGoods_id());
    		paraMap.put("order_id", taskFeeDetailInfo.getOrder_id());
    		
    		//商品受注明细存在性判定
    		int count=0;
    		List<TaskFeeDetailInfoDto> taskList= searchDao.checkGoodsByGoodsIdAndOrderId(paraMap);
    		if(taskList != null && taskList.size() > 0){
    			count=taskList.size();
    			String serviceGoodsOrderId=taskList.get(0).getService_goods_order_id();
    			taskFeeDetailInfo.setService_goods_order_id(serviceGoodsOrderId);
    		}
    		
			if(count>0){
				//商品受注明细存在場合、更新する
				searchDao.updateGoodsDetailInfo(taskFeeDetailInfo);
			}else{
				String serviceGoodsOrderId = CommonHelper.getSequence(Constants.TB_SERVICE_GOODS_ORDER_DETAIL);
				taskFeeDetailInfo.setService_goods_order_id(serviceGoodsOrderId);//商品受注明细Id
				//商品受注明细存在しない場合、追加する
				searchDao.insertGoodsDetailInfo(taskFeeDetailInfo);
			}
    }
    

}
